<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta charset='utf-8'>
        <meta name="author" content="order by dede58.com"/>
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<title>订单信息</title>
		<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta http-equiv="Cache-Control" content="no-siteapp">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" type="text/css" href="css/base.css" />
		<link rel="stylesheet" type="text/css" href="css/common.css" />
		<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="js/jquery.SuperSlide.2.1.js"></script>
		<script src="js/head.js"></script>
	</head>
	<script>
		$(function(){
			let nickname = "${sessionScope.customer.nickname}";
			let content = "";
			if(nickname!=""){
				content = "<span class=\"fl\">欢迎</span>"+
						"<a href=\"grxx.jsp\" class=\"fl\">"+nickname+"</a>"+
						"<span class=\"fl\">进入商城</span>"+
						"<a href=\"../LoginServlet?op=customerLogout\" class=\"fl\">退出登陆</a>";
			}else{
				content = "<span class=\"fl\">您好，请</span>"+
						"<a href=\"sign.jsp\" class=\"fl\">登录</a>";
			}
			$("#customerInfo").html(content);
		});
			
	</script>
	
	<script type="text/javascript">
		$(function(){
			/* 创建一个查询方法通过游戏编号查询游戏信息添加入购物车*/
			function s(){
				$.ajax({
					async:true,
					type:"GET",
					url:"../OrderServlet",
					data:{
						op:"find",
						orderNo:"0",
						customerId:${sessionScope.customer.customerId}
					},
					contentType:"application/x-www-form-urlencoded",
					dataType:"json",
					success:function(result,status,xhr){
						let count = 0;
						$.each(result.data,function(index,games){
							count = index + 1;
						});
						$("#shopCount").text("购物车（"+count+"）");
						
					},
					
				});	
			}
			/* 调用方法通过游戏编号查询游戏信息添加入购物车*/
			s();
		});
		</script>
	
	<body>
		

		<!--Main-wrap-->
		<div class="main-wrap graybg pt40 pb40" id="cen" style="margin-top: 86px;">
			<div class="js-box wrapper white-box">

				<!--goodssale-->
				<div class="goodssale">
					<div class="title line-bot"><span class="fs18 pl20 ml40 darkgray">游戏信息</span></div>
					<table class="table_1 table_goods" border="0" cellpadding="0" cellspacing="0" id="gameInfo">
						<!-- <tr class="line-bot">
							<td width="599">
								<p class="o-goods-info clearfix  ">
									<a href="#" class="fl"><span><img src="upload/2.jpg" alt=""></span></a>
									<span class="fl tit mt10">墙角数枝梅，凌寒独自开</span>
								</p>
							</td>
							<td width="148">29.90元*1</td>
							<td width="128">有货</td>
							<td width="177"><span class="orange">29.90元</span></td>
						</tr>
						<tr class="line-bot">
							<td>
								<p class="o-goods-info clearfix  ">
									<a href="#" class="fl"><span><img src="upload/2.jpg" alt=""></span></a>
									<span class="fl tit mt10">墙角数枝梅，凌寒独自开</span>
								</p>
							</td>
							<td>29.90元*1</td>
							<td>有货</td>
							<td><span class="orange">29.90元</span></td>
						</tr> -->
					</table>
					<div class="sale-info pt10 pb10 clearfix">
						<div class="fr total-amount mb30">
							<p class="mt20 fr">
								<span class="fs16 darkgray clearfix">商品总价：<em class="fr orange fs24 f-arial" id="sum">¥0</em></span>
							</p>
							<p class="mt10 fr">
								<a href="javascript:void(0)" class="fr orange-but fs20 radius3" id="submitOrder">提交订单</a>
							</p>
						</div>
					</div>
				</div>
				<!--/end-->

			</div>
		</div>
		<!--/end-->
		<script type="text/javascript">
		$(function(){
			
			let id = ${!empty sessionScope.customer.customerId} ?　"${sessionScope.customer.customerId}" : 0;
			let gamesId = ${empty param.gamesId} ? "0" : "${param.gamesId}";
			let sum = ${empty param.sum} ? "0" : "${param.sum}";
			let array = ${empty param.array} ? "0" : [${param.array}];
			
			// 点击提交订单先检查是否登录
			$("#submitOrder").click(function(){
				if(id!=0&&gamesId!="0"){
					/* 当点击提交订单即在数据库创建一条未支付的订单信息以及订单详情 */
					$.ajax({
						async:true,
						type:"GET",
						url:"../OrderServlet",
						data:{
							op:"addOrderInfo",
							gamesId:gamesId,
							customerId:id
						},
						contentType:"application/x-www-form-urlencoded",
						dataType:"json",
						success:function(result,status,xhr){
							
							if(result.status == 1){
								let orderNo = result.data;
								orderNo1=orderNo.substring(0,9);
								orderNo2=orderNo.substring(9);
								window.location.href="fukuan.jsp?gamesId=${param.gamesId}&orderNo1="+orderNo1+"&orderNo2="+orderNo2;
							}else{
								alert(result.message);
							}
							
						},
					});
					
				}else if(sum!="0"&&array!="0"){
					
					let gamesIdArray = null;
					for(let i = 0; i < array.length; i++){
						if(i!=0){
							gamesIdArray += "-";
						}
						gamesIdArray += array[i];
					}
					$.ajax({
						async:true,
						type:"GET",
						url:"../OrderServlet",
						data:{
							op:"addMoreOrderInfo",
							gamesIdArray:gamesIdArray,
							customerId:id,
							sum:sum
						},
						contentType:"application/x-www-form-urlencoded",
						dataType:"json",
						success:function(result,status,xhr){
							
							if(result.status == 1){
								let orderNo = result.data;
								orderNo1=orderNo.substring(0,9);
								orderNo2=orderNo.substring(9);
								window.location.href="fukuan.jsp?gamesIdArray="+gamesIdArray+"&sum="+sum+"&orderNo1="+orderNo1+"&orderNo2="+orderNo2;
							}else{
								alert(result.message);
							}
							
						},
					});
					
					
					
				}else{
					alert("请先登录才能购买");
				}
			});
		});
		
		</script>
		
		
		
		
		
		
<script type="text/javascript">
$(function(){
	// 查询购物车中多个游戏的合计订单
	let sum = ${empty param.sum} ? "0" : "${param.sum}";
	let array = ${empty param.array} ? "0" : [${param.array}];
	if(sum!="0"&&array!="0"){
		let content = "<tr>"+
	    
		"<th width=\"40%\">游戏</th>"+
		"<th width=\"14%\">单价(元)</th>"+
		"<th width=\"12%\">数量</th>"+
		"<th width=\"14%\">小计(元)</th>"+
		
		"</tr>";
		for(var i=0;i<array.length;i++){
			$.ajax({
				async:false,
				type:"GET",
				url:"../GamesServlet",
				data:{
					op:"find",
					gamesId:array[i]
				},
				contentType:"application/x-www-form-urlencoded",
				dataType:"json",
				success:function(result,status,xhr){

						content += "<tr class=\"line-bot\">"+
							
							"<td>"+
								"<p class=\"o-goods-info clearfix\">"+
									"<a href=\"#\" class=\"fl\"><span><img src=\"/gamestore/FileDownloadServlet?type=image&fileName="+result.data.image+"\" alt=\"\"></span></a>"+
									"<span class=\"fl tit mt10\">"+result.data.gamesName+"</span>"+
								"</p>"+
							"</td>"+
							"<td>"+result.data.price+"</td>"+
							"<td>"+
								"<p class=\"clearfix\">"+
									"1"+
								"</p>"+
							"</td>"+
							"<td><span class=\"orange\" id=\"price\">"+result.data.price+"</span></td>"+
							
						"</tr>";
						
					
					
					
				},
				
			});
			
		}
		$("#gameInfo").html(content);
		$("#sum").text("¥"+sum);
		
	}
	// 查询立即购买的单个游戏的信息
	let gamesId = ${empty param.gamesId} ? "0" : "${param.gamesId}";
	if(gamesId!="0"){
		$.ajax({
			async:true,
			type:"GET",
			url:"../GamesServlet",
			data:{
				op:"find",
				gamesId:gamesId
			},
			contentType:"application/x-www-form-urlencoded",
			dataType:"json",
			success:function(result,status,xhr){
				let content = "<tr>"+
			    
				"<th width=\"40%\">游戏</th>"+
				"<th width=\"14%\">单价(元)</th>"+
				"<th width=\"12%\">数量</th>"+
				"<th width=\"14%\">小计(元)</th>"+
				
				"</tr>";

					content += "<tr class=\"line-bot\">"+
						
						"<td>"+
							"<p class=\"o-goods-info clearfix\">"+
								"<a href=\"#\" class=\"fl\"><span><img src=\"/gamestore/FileDownloadServlet?type=image&fileName="+result.data.image+"\" alt=\"\"></span></a>"+
								"<span class=\"fl tit mt10\">"+result.data.gamesName+"</span>"+
							"</p>"+
						"</td>"+
						"<td>"+result.data.price+"</td>"+
						"<td>"+
							"<p class=\"clearfix\">"+
								"1"+
							"</p>"+
						"</td>"+
						"<td><span class=\"orange\" id=\"price\">"+result.data.price+"</span></td>"+
						
					"</tr>";
					
				
				$("#gameInfo").html(content);
				$("#sum").text("¥"+result.data.price);
			},
			
		});
	}
	
	
});
</script>

<script type="text/javascript">
	


</script>





		<!--footer star-->
		<div class="footer clearfix">
			<div class="content clearfix">
				<div class="top clearfix">
					<div class="list clearfix fl box-s">
						<div class="part icon1 box-s">
							<h3>专业</h3>
							<p>拥有资深游戏顾问和先进交易平台，安全交易，快捷支付。</p>
						</div>
					</div>
					<div class="list clearfix fl box-s">
						<div class="part icon2 box-s">
							<h3>保真</h3>
							<p>阵容强大的游戏评鉴团，确保平台上的游戏货真价实。</p>
						</div>
					</div>
					<div class="list clearfix fl box-s">
						<div class="part icon3 box-s">
							<h3>保值</h3>
							<p>为您精选具备收藏价值的游戏作品，助您的资产保值、增值。</p>
						</div>
					</div>
				</div>
				<div class="bottom clearfix">
					<div class="left clearfix fl">
						<div class="list clearfix">
							<div class="shang clearfix">
								<p>新手指南</p>
								<span></span>
							</div>							
							<div class="xia clearfix">
								<ul>
									<li><a href="scgmlc.html">购买流程</a></li>
									<li><a href="cjwt.html">常见问题</a></li>
								</ul>
							</div>
						</div>
						<div class="list clearfix">
							<div class="shang clearfix">
								<p>账户管理</p>
								<span></span>
							</div>							
							<div class="xia clearfix">
								<ul>
									<li><a href="zhcz.html">账户充值</a></li>
									<li><a href="zhtx.html">账户提现</a></li>
									<li><a href="zffs.html">支付方式</a></li>
								</ul>
							</div>
						</div>						
						<div class="list clearfix">
							<div class="shang clearfix">
								<p>服务合作</p>
								<span></span>
							</div>							
							<div class="xia clearfix">
								<ul>
									<li><a href="friend-link.html">友情链接</a></li>
									<li><a href="ysjrz.html">玩家入驻</a></li>
								</ul>
							</div>
						</div>
						<div class="list clearfix">
							<div class="shang clearfix">
								<p>关于我们</p>
								<span></span>
							</div>							
							<div class="xia clearfix">
								<ul>
									<li><a href="gsjj.html">公司简介</a></li>
									<li><a href="contact.html">联系我们</a></li>
									<li><a href="jrwm.html">加入我们</a></li>
								</ul>
							</div>
						</div>
						<div class="list clearfix">
							<div class="shang clearfix">
								<p>售后服务</p>
								<span></span>
							</div>							
							<div class="xia clearfix">
								<ul>
									<li><a href="wlsm.html">交易说明</a></li>
									<li><a href="mzsm.html">免责声明</a></li>
								</ul>
							</div>
						</div>
					</div>
					<div class="middle clearfix fl">
						<ul>
							<li><img src="upload/ewm.jpg"/></li>
							<li><img src="upload/ewm.jpg"/></li>
						</ul>
					</div>
					<div class="right clearfix fr">
						<p class="bt">免费咨询热线：</p>
						<p class="tel">400-000-0000</p>
						<p class="fu-bt">(周一到周五8:00-22:00)</p>
					</div>
				</div>
			</div>
			<div class="banquan clearfix ta-center">
				Copyright © 2021 厦门游戏商城(xiamenyouxishangcheng). All Rights Reserved. 
			</div>
		</div>
		<!--footer end-->

		<div id="mask">
			<div class="alert-box radius8">
				<h3 class="fs20">添加收货地址 <span class="close"></span></h3>
				<div class="address-form box-s">
					<form action="">
						<p class="mb20 clearfix">
							<label class="fl">收货人：</label>
							<input type="text" placeholder="姓名" value="" placeholder="姓名" class="fl ml5">
							<em class="fl red lh40 ml10">*</em>
						</p>
						<p class="mb20 clearfix">
							<label class="fl">手机：</label>
							<input type="text" placeholder="手机" value="" placeholder="手机" class="fl ml5">
							<em class="fl red lh40 ml10">*</em>
						</p>
						<p class="mb20 clearfix">
							<label class="fl">地址：</label>
							<select name="" id="" class="fl ml5">
								<option value="0">省份/直辖市</option>
								<option value="1">安徽省</option>
							</select>
							<select name="" id="" class="fl ml5">
								<option value="0">城市</option>
								<option value="1">合肥市</option>
							</select>
							<select name="" id="" class="fl ml5">
								<option value="0">区县</option>
								<option value="1">经开区</option>
							</select>
						</p>
						<p class="mb20 clearfix">
							<label class="fl"></label>
							<input type="text" value="" placeholder="详细地址" class="fl ml5">
							<em class="fl red lh40 ml10">*</em>
						</p>
						<p class="mb20 clearfix">
							<label class="fl">邮政编码：</label>
							<input type="text" placeholder="邮政编码" value="" class="fl ml5">
						</p>
						<p class="mb20 clearfix">
							<label class="fl"></label>
							<input type="button" value="保存" class="fl orange-but radius3 ml5">
							<input type="button" value="取消" class="fl gray-but radius3 ml10">
						</p>
					</form>
				</div>
			</div>
		</div>
	</body>
	<script src="js/other.js" type="text/javascript" ></script>

</html>